<?php 
		$roomno = $_GET['viewcomments'];
		$username = $_SESSION['username'];        $query = "select * from user where username='$username'";        $result = mysql_query($query);

		if (!$result) {
  				  echo '<script>						<!-- 						 window.location= "http://www.mariokartchallenger.com"									//-->						</script>'; die();		}

		$user = mysql_fetch_array($result);
		$temp = $user['nick']; 

		$query = "select * from gamematch where id='$roomno'";       	$result = mysql_query($query); 
		$roomstuff = mysql_fetch_array($result); 

		$host = $roomstuff['host'];
		$descript = $roomstuff['descr'];

		$query = "select * from user where username='$host'";        $result = mysql_query($query);
		$hostdata = mysql_fetch_array($result); 

		$query = "select * from messages where room='$roomno'";        $result = mysql_query($query);
		$commentdata = mysql_fetch_array($result); 
?>

<table height="320px" width="603px">
				<tr><td id="info" valign="top">
					<table cellpadding="0" cellspacing="0" >
						<tr><td width="395px" valign="top">
						<?php include 'navbar.php'; ?>
						</td>
						<td>&nbsp;</td>
						<td valign="top">
							<table cellpadding="0" cellspacing="0" border="0" align="right" width="185px"><tr><td>
							<?php
							if (empty($temp)) { include 'guestgreet.php'; } else{ include 'usergreet.php'; } ?>
							</td></tr><tr><td id="login"><div align="right"><span style="font-size:12px"><? echo $user['nick']; ?></span> ( <strong><?php if (is_authed()) { echo '<a href="index.php?act=logout">Logout</a>';} else {echo '<a href="register.php">Register</a> | <a href="index.php">Log In</a> ';} ?> </strong> )</div></td></tr></table>
					

						</td></tr>
					</table>

					<table cellpadding="0" cellspacing="0"><tr><td width="385px" valign="top">
						<div>						<b class="inbox">						<b class="inbox1"><b></b></b>						<b class="inbox2"><b></b></b>						<b class="inbox3"></b>						<b class="inbox4"></b>						<b class="inbox5"></b></b>						<div class="inboxfg">
							<table cellpadding="0" cellspacing="0" width="385" border="0">
								<tr><td width="25px" style="padding-left : 5px"><a href="index.php?showroom=<? echo $roomno; ?>" ><img src="img/back.png" border="0"></a></td>
								<td width="360px" style="padding-right : 5px"><h3><div align="right">comments on <? echo $roomstuff['battlename']; ?></div></h3></td>
							</tr></table>
					  	</div>  						<b class="inbox">  						<b class="inbox5"></b>  						<b class="inbox4"></b>  						<b class="inbox3"></b>  						<b class="inbox2"><b></b></b>  						<b class="inbox1"><b></b></b></b>						</div>

					<p><div id="regtext">
					<?php 
						$query = "select * from messages where room = '$roomno' order by timestamp desc limit 5"; 
 						$numresults=mysql_query($query);
					    $numrows=mysql_num_rows($numresults);

						$result = mysql_query($query);
						$count = 1;

					    $commentuser = array ();
					    $commentdata = array ();
						while($row = mysql_fetch_array($result)){
							$commentuser[$count] = $row['userid']; $commentdata[$count] = $row['message'];
							$count++;						}
					 

						if (empty($commentuser[1])) { echo 'No comments have been left.<br />'; } 

						if (!empty($commentuser[1])) {

								$query = "select * from user where userid = '$commentuser[1]' limit 1"; 
 								$results=mysql_query($query);
					    		$useris=mysql_fetch_array($results);
	
								echo "<table width='385px' cellpadding='0' cellspacing='0' border='0'><tr><td width='50px' style='padding-left:10px'>
											<span style='font-size:12px'>";
								if ($useris['username'] == $host && $useris['userid'] != '1') { echo "<a style='color: blue' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								elseif ($useris['userid'] == '1') { echo "<a style='color: red' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								else { echo"<a style='color: #444444' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'>" . $useris['nick'] ."</a>";}
								echo "			 </span>
											</td>
											<td align='right' style='padding-right:5px'><span style='font-size:10px'>". $commentdata[1] ."</span> </td>
										</tr></table>
										<hr style ='padding-right: 3px; color: #fff; background-color: #fff; border: 1px dotted #444444; border-style: none none dotted'/>" ;
						}
						if (!empty($commentuser[2])) {

								$query = "select * from user where userid = '$commentuser[2]' limit 1"; 
 								$results=mysql_query($query);
					    		$useris=mysql_fetch_array($results);
	
								echo "<table width='385px' cellpadding='0' cellspacing='0' border='0'><tr><td width='50px' style='padding-left:10px'>
											<span style='font-size:12px'>";
								if ($useris['username'] == $host && $useris['userid'] != '1') { echo "<a style='color: blue' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								elseif ($useris['userid'] == '1') { echo "<a style='color: red' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								else { echo"<a style='color: #444444' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'>" . $useris['nick'] ."</a>";}
								echo "			 </span>
											</td>
											<td align='right' style='padding-right:5px'><span style='font-size:10px'>". $commentdata[2] ."</span> </td>
										</tr></table>
										<hr style ='padding-right: 3px;color: #fff; background-color: #fff; border: 1px dotted #444444; border-style: none none dotted'/>" ;
						}
						if (!empty($commentuser[3])) {

								$query = "select * from user where userid = '$commentuser[3]' limit 1"; 
 								$results=mysql_query($query);
					    		$useris=mysql_fetch_array($results);
	
								echo "<table width='385px' cellpadding='0' cellspacing='0' border='0'><tr><td width='50px' style='padding-left:10px'>
											<span style='font-size:12px'>";
								if ($useris['username'] == $host && $useris['userid'] != '1') { echo "<a style='color: blue' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								elseif ($useris['userid'] == '1') { echo "<a style='color: red' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								else { echo"<a style='color: #444444' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'>" . $useris['nick'] ."</a>";}
								echo "			 </span>
											</td>
											<td align='right' style='padding-right:5px'><span style='font-size:10px'>". $commentdata[3] ."</span> </td>
										</tr></table>
										<hr style ='padding-right: 3px;color: #fff; background-color: #fff; border: 1px dotted #444444; border-style: none none dotted'/>" ;
						}
						if (!empty($commentuser[4])) {

								$query = "select * from user where userid = '$commentuser[4]' limit 1"; 
 								$results=mysql_query($query);
					    		$useris=mysql_fetch_array($results);
	
								echo "<table width='385px' cellpadding='0' cellspacing='0' border='0'><tr><td width='50px' style='padding-left:10px'>
											<span style='font-size:12px'>";
								if ($useris['username'] == $host && $useris['userid'] != '1') { echo "<a style='color: blue' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								elseif ($useris['userid'] == '1') { echo "<a style='color: red' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								else { echo"<a style='color: #444444' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'>" . $useris['nick'] ."</a>";}
								echo "			 </span>
											</td>
											<td align='right' style='padding-right:5px'><span style='font-size:10px'>". $commentdata[4] ."</span> </td>
										</tr></table>

										<hr style ='padding-right: 3px;color: #fff; background-color: #fff; border: 1px dotted #444444; border-style: none none dotted'/>" ;
						}
						if (!empty($commentuser[5])) {

								$query = "select * from user where userid = '$commentuser[5]' limit 1"; 
 								$results=mysql_query($query);
					    		$useris=mysql_fetch_array($results);
	
								echo "<table width='385px' cellpadding='0' cellspacing='0' border='0'><tr><td width='50px' style='padding-left:10px'>
											<span style='font-size:12px'>";
								if ($useris['username'] == $host && $useris['userid'] != '1') { echo "<a style='color: blue' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								elseif ($useris['userid'] == '1') { echo "<a style='color: red' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'><strong>" . $useris['nick'] ."</strong></a>";}
								else { echo"<a style='color: #444444' href='http://www.mariokartchallenger.com/index.php?showuser=". $useris['userid'] ."'>" . $useris['nick'] ."</a>";}
								echo "			 </span>
											</td>
											<td align='right' style='padding-right:5px'><span style='font-size:10px'>". $commentdata[5] ."</span> </td>
										</tr></table>

										<hr style ='padding-right: 3px;color: #fff; background-color: #fff; border: 1px dotted #444444; border-style: none none dotted'/>" ;
						}

						echo '<br />';
     					if (is_authed()) {include 'comments_form.inc.php';}			
						echo '<span style="font-size:12px">';

						// check for an empty string and display a message.
						if ($_POST['comment'] == "" && isset($_POST['submit']))
						  {
						  $comments_error = 'What a failure you have just become...';
						  }

						if (empty($comments_error) && isset($_POST['submit'])) {
							$message = $_POST['comment'];
							$time = time();
							$theid = $user['userid'];
							$query = "insert into messages (room, message, timestamp, userid) values ('$roomno', '$message', '$time', '$theid')";
							mysql_query($query);
							echo '<script>							<!-- 								 window.location= "http://www.mariokartchallenger.com/index.php?viewcomments='.$roomno.'"							//-->							</script>';
						}

					?>


</div>
					</td><td valign="top">
                         <div align="right">
							<?php
                            if (is_authed()) { include 'sidebar.php';} elseif (!is_authed()) { echo '' ;} ?>						</div>
					</td></tr></table>
				
					</td></tr>
			</table>
			</td>
		</tr>
	</table>


<?php include 'footer.php' ?>
